<template>
  <div>
    <el-table
      :data="cateList"
      style="width: 100%; margin-bottom: 20px"
      row-key="id"
      border
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
      <el-table-column prop="id" label="分类编号"> </el-table-column>
      <el-table-column prop="catename" label="分类名称"> </el-table-column>
      <el-table-column label="图片">
        <template slot-scope="scope">
          <div>
            <!-- <span>{{scope.row.img}}</span> -->
            <img :src="$pre + scope.row.img" alt="" />
          </div>
        </template>
      </el-table-column>
      <el-table-column label="状态">
        <template slot-scope="scope">
          <div>
            <el-button type="primary" v-if="scope.row.status == 1"
              >启 用</el-button
            >
            <el-button type="success" v-else>禁 用</el-button>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <div>
            <el-button type="info" @click="edit(scope.row.id)">编 辑</el-button>
             <v-del @del="del(scope.row.id)"></v-del>
          </div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
import { mapGetters, mapActions } from "vuex";
import { cateLete } from "../../../request/api";
import { successAlert, warningAlert } from "../../../utils/alert";
export default {
  props: [],
  components: {},
  data() {
    return {};
  },
  computed: {
    ...mapGetters({
      cateList: "cate/list",
    }),
  },
  methods: {
    ...mapActions({
      asyncCateList: "cate/asyncList",
    }),
    // 点击编辑
    edit(id) {
      // 通知父组件，我点了编辑
      this.$emit("edit",id);
    },
      del(id) {
     cateLete({ id:id }).then((res) => {
      if (res.data.code == 200) {
        // 成功的提示窗
        successAlert(res.data.msg);
        // 刷新列表数据
        this.asyncCateList();
      } else {
        // 失败的提示窗
        warningAlert(res.data.msg);
      }
    });
  },
  },

  mounted() {
    // 页面一进来就请求列表数据
    this.asyncCateList();
  },
};
</script>
<style scoped>
img {
  width: 150px;
  height: 100px;
}
</style>